﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using NS.Utilities;
using NS.BLL.Systems;
using BLL;
using Model;

public partial class Platform_CouponsManage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            GridViewDataBind();
        }
    }

    private void GridViewDataBind()
    {
        FGridView1.SQLString = CouponsSchemeService.GetAllCouponsScheme_SQL();
        FGridView1.PKey = "SchemeID";
        FGridView1.OrderName = "SchemeID DESC";
        FGridView1.BindData();
        FGridView1.AddControl();
    }
    protected void btnBindData_Click(object sender, EventArgs e)
    {
        GridViewDataBind();
    }
    protected void btnDel_Click(object sender, EventArgs e)
    {
        string SchemeID = ((Button)sender).CommandArgument.ToString();
        CouponsSchemeService.DeleteCouponsSchemeBySchemeID(Convert.ToInt32(SchemeID));
        GridViewDataBind();
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        CouponsScheme Model = new CouponsScheme();
        Model.CouponName = txtCouponName.Text.Trim();
        Model.Quantity = Convert.ToInt32(txtQuantity.Text.Trim());
        Model.OldPrice = Convert.ToDecimal(txtOldPirce.Text.Trim());
        Model.PrePrice = Convert.ToDecimal(txtPrePirce.Text.Trim());
        Model.ValidDays = Convert.ToInt32(txtValidDays.Text.Trim());
        Model.Scope = txtScope.Text.Trim();
        Model.Explain = txtExplain.Text.Trim();
        if (CouponsSchemeService.AddCouponsScheme(Model) > 0)
        {
            GridViewDataBind();
        }
        else
        {
            MessageBox.ShowSaveError(this);
        }
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        GridBind();
    }

    public void GridBind()
    {
        CouponsScheme Model = new CouponsScheme();
        //Model.CouponName = txtCouponName.Text.Trim();
        //Model.OldPrice = Convert.ToDecimal(txtValidDays.Text.Trim());
        //Model.PrePrice = Convert.ToDecimal(txtOldPirce.Text.Trim());
        FGridView1.SQLString = CouponsSchemeService.GetAllCouponsScheme_SQL(txtCouponName.Text.Trim(), txtValidDays.Text.Trim(), txtOldPirce.Text.Trim());
        FGridView1.PKey = "SchemeID";
        FGridView1.OrderName = "SchemeID";
        FGridView1.BindData();
        FGridView1.AddControl();
    }

}